package com.wnhz.work.yz.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.wnhz.work.yz.MyApplication;

/**
 * Created by wanghongchuang
 * on 2016/8/25.
 * email:844285775@qq.com
 */
public class Prefer {
    private static final String TAG = "Prefer";
    private static final String PREFERENCE_FILE = "prefer_config";

    private static Prefer mInstance;
    private SharedPreferences mPref;
    private SharedPreferences.Editor editor;

    private final String KEY_IS_LOGIN = "KEY_IS_LOGIN";
    private final String KEY_TOKEN = "KEY_TOKEN";

    private final String KEY_AVATAR = "KEY_AVATAR";
    private final String KEY_SEX = "KEY_SEX";
    private final String KEY_NAME = "KEY_NAME";
    private final String KEY_JYMM = "KEY_JYMM";
    private final String KEY_BANK = "KEY_BANK";
    private final String KEY_ISBOUNDPHONE = "KEY_ISBOUNDPHONE";
    private final String KEY_L0GINTYPE = "KEY_LOGINTYPE";
    private final String KEY_GENDER = "KEY_GENDER";
    private final String KEY_OPENID = "KEY_OPENID";
    private final String KEY_IMAGE = "KEY_IMAGE";
    private final String KEY_NICKNAME = "KEY_NICKNAME";
    private final String KEY_REGTYPE = "KEY_REGTYPE";
    private final String KEY_BANKPHONE = "KEY_BANKPHONE";

    private final String KEY_HTPHONE = "KEY_HTPHONE";
    private final String KEY_HTADDRESS = "KEY_HTADDRESS";
    private final String KEY_HTJIAFANG = "KEY_HTJIAFANG";
    private final String KEY_HTCHUANZHEN = "KEY_HTCHUANZHEN";
    private final String KEY_HTJIAOHUO = "KEY_HTJIAOHUO";
    private final String KEY_HTSHOUHUOREN = "KEY_HTSHOUHUOREN";
    private final String KEY_HTSHENFENZHENG = "KEY_HTSHENFENZHENG";
    private final String KEY_MARKET_PRICE = "KEY_MARKET_PRICE";
    private final String Test="test";
    private final String REDUCE_BTN = "REDUCE_BTN";

    public static Prefer getInstance() {
        if (null == mInstance) {
            mInstance = new Prefer();
        }
        return mInstance;
    }

    private Prefer() {
        mPref = MyApplication.getInstance().getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
    }


    /**
     * 是否登录
     */
    public void setLogined(boolean isLogin) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putBoolean(KEY_IS_LOGIN, isLogin);
        editor.commit();
    }

    public boolean isLogined() {
        return mPref.getBoolean(KEY_IS_LOGIN, false);
    }

    //token
    public void setToken(String token) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_TOKEN, token);
        editor.commit();
    }

    public String getToken() {
        return mPref.getString(KEY_TOKEN, "");
    }

    //合同地址
    public void setHTAddress(String Address) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTADDRESS, Address);
        editor.commit();
    }

    public String getHTAddress() {
        return mPref.getString(KEY_HTADDRESS, "");
    }


    //手机号
    public void setHTPhone(String token) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTPHONE, token);
        editor.commit();
    }

    public String getHTPhone() {
        return mPref.getString(KEY_HTPHONE, "");
    }



    //购物车 加号 防止暴击
    public void setTest(int test) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(Test, test);
        editor.commit();
    }

    public int getTest() {
        return mPref.getInt(Test, 0);
    }

    public void setTestReduce(int reduce) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(REDUCE_BTN, reduce);
        editor.commit();
    }

    public int getTestReduce() {
        return mPref.getInt(REDUCE_BTN, 0);
    }

    //合同甲方
    public void setHTJiaFang(String jiafang) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTJIAFANG, jiafang);
        editor.commit();
    }

    public String getHTJiaFang() {
        return mPref.getString(KEY_HTJIAFANG, "");
    }


    //传真
    public void setHTChuanZhen(String chuanzhen) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTCHUANZHEN, chuanzhen);
        editor.commit();
    }

    public String getHTChuanZhen() {
        return mPref.getString(KEY_HTCHUANZHEN, "");
    }


    //交货地址
    public void setHTJioaHuo(String jiaohuo) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTJIAOHUO, jiaohuo);
        editor.commit();
    }

    public String getHTJioaHuo() {
        return mPref.getString(KEY_HTCHUANZHEN, "");
    }

    //收货人
    public void setHTShouHuoren(String shouhuoren) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTSHOUHUOREN, shouhuoren);
        editor.commit();
    }

    public String getHTShouHuoren() {
        return mPref.getString(KEY_HTSHOUHUOREN, "");
    }


    //收货人身份证号码
    public void setHTShenFenzheng(String shouhuoren) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_HTSHENFENZHENG, shouhuoren);
        editor.commit();
    }

    public String getHTShenFenzheng() {
        return mPref.getString(KEY_HTSHENFENZHENG, "");
    }


    //头像
    public void setTouxiang(String avatar) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_AVATAR, avatar);
        editor.commit();
    }

    public String getTouxiang() {
        return mPref.getString(KEY_AVATAR, "");
    }

    //已绑定的手机号
    public void setBoundphone(String boundphone) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_BANKPHONE, boundphone);
        editor.commit();
    }

    public String getBoundPhone() {
        return mPref.getString(KEY_BANKPHONE, "");
    }



    //名称
    public void setName(String name) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_NAME, name);
        editor.commit();
    }

    public String getName() {
        return mPref.getString(KEY_NAME, "");
    }

    //性别
    public void setSex(String sex) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_SEX, sex);
        editor.commit();
    }

    public String getSex() {
        return mPref.getString(KEY_SEX, "");
    }


    //是否设置交易密码
    public void setJiaoyi(String jiaoyi){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_JYMM, jiaoyi);
        editor.commit();
    }

    public String getJiaoyi() {
        return mPref.getString(KEY_JYMM, "");
    }

    //是否设置默认银行卡
    public void setBank(String bank){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_BANK, bank);
        editor.commit();
    }

    public String getBank() {
        return mPref.getString(KEY_BANK, "");
    }

    //是否设置默认银行卡
    public void setMarketPrice(String price){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_MARKET_PRICE, price);
        editor.commit();
    }

    public String getMarketPrice() {
        return mPref.getString(KEY_MARKET_PRICE, "");
    }


    //登录类型  1 手机号  2 微信  3qq
    public void setLoginType(String loginTypoe){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_L0GINTYPE, loginTypoe);
        editor.commit();
    }

    public String getLoginType() {
        return mPref.getString(KEY_L0GINTYPE, "");
    }

    //openId
    public String getOpenId() {
        return mPref.getString(KEY_OPENID, "");
    }

    public void setOpenId(String openId) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_OPENID, openId);
        editor.commit();
    }

    public String getImage() {
        return mPref.getString(KEY_IMAGE, "");
    }

    public void setImage(String profileImage) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_IMAGE, profileImage);
        editor.commit();
    }

    public String getNickname() {
        return mPref.getString(KEY_NICKNAME, "");
    }

    public void setNickname(String nickname) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_NICKNAME, nickname);
        editor.commit();
    }

    public void setGender(String gender) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_GENDER, gender);
        editor.commit();
    }

    //性别
    public String getGender() {
        return mPref.getString(KEY_GENDER, "");
    }

    public void setRegType(String regType) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(KEY_REGTYPE, regType);
        editor.commit();
    }

    //性别
    public String getRegType() {
        return mPref.getString(KEY_REGTYPE, "");
    }

    //退出登录后清除缓存数据
    public void clearData() {
        SharedPreferences.Editor editor = mPref.edit();
        editor.clear();
        editor.commit();
    }
}
